package com.example.ruiji.config.webmvc;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ResourceUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Author:BaiYiChen
 * Date:2022/4/19 16:17
 *
 * @author BaiYiChen
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
  @Override
  public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/").setViewName("index");
    registry.addViewController("/index").setViewName("index");
    registry.addViewController("/writeArticle").setViewName("writeArticle");
    registry.addViewController("/submit").setViewName("submit_2");
    registry.addViewController("/showDetail").setViewName("showDetail");
  }
  
  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/static/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX + "/static/");
  }
  //  @Override
//  public void addInterceptors(InterceptorRegistry registry) {
//    registry.addInterceptor(new MyInterceptors())
//            .addPathPatterns("/*")
//            .excludePathPatterns("/static/**","/","index");
//  }
//  @Bean
//  public MyInterceptors myInterceptors(){
//    return new MyInterceptors();
//  }
}
//class MyInterceptors implements HandlerInterceptor{
//  @Override
//  public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//    return HandlerInterceptor.super.preHandle(request, response, handler);
//  }
//}
